package com.ncu.weatherchina;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

class ViewHolder2{
    public TextView td_name;
    public TextView td_datail;
    public TextView td_values;

    View itemView;
    public ViewHolder2(View itemView){
        if (itemView ==null){
            throw new IllegalArgumentException("itemView can not be null!");
        }
        this.itemView=itemView;
        td_name=itemView.findViewById(R.id.td_name);
        td_datail=itemView.findViewById(R.id.td_datail);
        td_values=itemView.findViewById(R.id.td_values);
    }
}

public class ZhiShuAdapter extends BaseAdapter {
    private List<WeatherIndex> forecastList;
    private LayoutInflater layoutInflater;
    private Context context;
    private int currentPos=-1;
    private ViewHolder2 holder=null;
    public ZhiShuAdapter(Context context,List<WeatherIndex> forecastList){
        this.forecastList=forecastList;
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void setFocusItemPos(int pos){
        currentPos=pos;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return forecastList.size();
    }

    @Override
    public Object getItem(int position) {
        return forecastList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void remove(int index){
        forecastList.remove(index);
    }

    public void refreshDataSet(){
        notifyDataSetChanged();
    }
    public ImageView td_pic;
    public TextView td_datail;
    public TextView td_values;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView=layoutInflater.inflate(R.layout.item_layout_zhishu,null);
            holder=new ViewHolder2(convertView);
            convertView.setTag(holder);
        }
        else {
            holder= (ViewHolder2) convertView.getTag();
        }
        holder.td_name.setText(forecastList.get(position).getName());
        holder.td_datail.setText(forecastList.get(position).getDetail());
        holder.td_values.setText(forecastList.get(position).getValue());
        return convertView;
    }
}
